
const date = new Date()
const months = []
const days = []
const hours = []

for (let i = 1; i <= 12; i++) {
  if (i < 10) {
    i = '0' + i
  }
  months.push(i)
}

for (let i = 1; i <= 31; i++) {
  if (i < 10) {
    i = '0' + i
  }
  days.push(i)
}

for (let i = 1; i <= 24; i++) {
  hours.push(i + ":00")
}

const App = getApp();

Page({

  data: {
    showMake: true,
    showTime: false,
    months: months,
    month: 1,
    days: days,
    day: 2,
    hours: hours,
    hour: 5,
    date: '',
    value: [date.getMonth(), date.getDate() - 1, date.getHours() - 1],
    options: {},
  },
  onLoad: function (options) {
    // 加载页面数据
    //this.getPageData();
  },

  /**
   * 加载页面数据
   */
  getPageData: function (callback) {
    let _this = this;
    App._get('page/index', {
      page_id: _this.data.options.page_id || 0
    }, function (result) {
      // 设置顶部导航栏栏
      _this.setData(result.data);
      // 回调函数
      typeof callback === 'function' && callback();
    });
  },
  bindChange: function (e) {
    const val = e.detail.value
    this.setData({
      month: this.data.months[val[0]],
      day: this.data.days[val[1]],
      hour: this.data.hours[val[2]],
      date: this.data.months[val[0]] + '-' + this.data.days[val[1]] + ' ' + this.data.hours[val[2]]
    })
  },
  setDate(){
    let time = this.data.date;
    let month = date.getMonth() + 1;
    let days = date.getDate();
    let hours = date.getHours() + ":00";
    if (!time){
      if (month < 10){
        "0"+ month
      }
      if (days < 10) {
        "0" + days
      }
      time = month +"-"+ days +" "+ hours
    }
    this.triggerEvent('getDate', time)
  },
  showTime(e) {
    this.setData({
      showTime: !this.data.showTime
    })
  },
  closeMake() {
    this.setData({
      showMake: false
    })
  }
});